<?php
require_once '../../../../config.php';


  $fileId = $_REQUEST['path'] . "/content";
  

  if (array_key_exists('fileType', $_REQUEST)) {
    $fileType = $_REQUEST['fileType'];
  }
  if (!isset($fileType)) {
    $doc = new DOMDocument;
    $payload = file_get_contents($host . "?" .  $_SERVER['QUERY_STRING'] . "&raw=1");
//	echo $host . "?" .  $_SERVER['QUERY_STRING'] . "&raw=1";
    $doc->loadXML($payload);
    $fileType = $doc->documentElement->localName;
  }
  if ($fileType == "dita") {
    $fileType = "ditabase";
  }

  $config = new DOMDocument;
  $config->load("../xsd/catalog.xml");
  $xpath = new DOMXPath($config);
  $xpath->registerNamespace("a", "urn:oasis:names:tc:entity:xmlns:xml:catalog");

  $schema = '../xsd/technicalContent/xsd/ditabase.xsd';
  $system = $xpath->evaluate("a:system[@uri = '$fileType.xsd']", $config->documentElement)->item(0);
  if ($system) {
    $schema = '../xsd/' . $system->getAttribute("xml:base") . $system->getAttribute("uri");
  }

  $docstring = "<?xml version='1.0' ?>
  <island>
    <canvas>
      <fileType>$fileType</fileType>
      <fileId>remote.php?path=" . $fileId . "</fileId>
      <schema>$schema</schema>
    </canvas>
  </island>";

  $doc = new DOMDocument;
  $doc->loadXML($docstring);
  $tpl = new DOMDocument;
  $tpl->load("view-xopus-island.xsl");
  $xsltproc = new XSLTProcessor;
  $xsltproc->importStylesheet($tpl);
  echo $xsltproc->transformToXML($doc);

